package wms_plugin

import (
	"gorm.io/gorm"
	"time"
	"wms-go/modules/m_utils"
)

type CreateBeforePlugin struct{}

func (t *CreateBeforePlugin) Name() string {
	return "create_before_plugin"
}

func (t *CreateBeforePlugin) Initialize(db *gorm.DB) error {
	return db.Callback().Create().Before("gorm:create").Register("createBefore", t.beforeCreate)
}

func (t *CreateBeforePlugin) beforeCreate(db *gorm.DB) {
	//设置ID
	db.Statement.SetColumn("id", m_utils.GenXid(), true)
	db.Statement.SetColumn("created_at", time.Now(), true)
	//db.Statement.SetColumn("update_time", time.Now(), true)
}
